/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Admin
 */
@Entity
@Table(name = "University")
@NamedQueries({
    @NamedQuery(name = "University.findAll", query = "SELECT s FROM University s"),
    @NamedQuery(name = "University.findByUniversityId", query = "SELECT s FROM University s WHERE s.id = :universityId"),
    @NamedQuery(name = "University.findByName", query = "SELECT s FROM University s WHERE s.name = :name"),
    @NamedQuery(name = "University.findByCredits", query = "SELECT s FROM University s WHERE s.city = :city")
})
public class University implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "UniversityId")
    private Long id;
    
    @Column(name = "Name")
    private String name;
    
    @Column(name = "City")
    private String city;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "university")
    private List<Faculty> faculties;

    public University(){
    }
    
    public University(String name, String city){
        this.name = name;
        this.city = city;
    }
    
    public List<Faculty> getFaculties() {
        return faculties;
    }

    public void setFaculties(List<Faculty> faculties) {
        this.faculties = faculties;
    }
    
    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof University)) {
            return false;
        }
        University other = (University) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return name + " (" + id + ")";
    }
    
}
